home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / PowerPlant / AGA Classes 1.2 / AGADemo / AGADemo Sources / AGADemoApp.cp < prev    next >
Encoding:
Text File  |  1996-06-05  |  7.2 KB  |  280 lines  |  [TEXT/CWIE]

  1. // ===========================================================================
  2. //    AGADemoApp.cp         ©1994-1995 Metrowerks Inc. All rights reserved.
  3. // ===========================================================================
  4. //
  5. //    This file contains the starter code for a PowerPlant application
  6.  
  7. #include "AGADemoApp.h"
  8.  
  9. #include <LGrowZone.h>
  10. #include <LWindow.h>
  11. #include <PP_Messages.h>
  12. #include <PP_Resources.h>
  13. #include <PPobClasses.h>
  14. #include <UDrawingState.h>
  15. #include <UMemoryMgr.h>
  16. #include <URegistrar.h>
  17. #include <LEditField.h>
  18.  
  19. #include "LAGADefaultOutline.h"
  20. #include "LAGAIconButton.h"
  21. #include "LAGAPushButton.h"
  22. #include "LAGACheckBox.h"
  23. #include "LAGAIndexTab.h"
  24. #include "LAGARadioButton.h"
  25. #include "LAGAEditField.h"
  26. #include "LAGAEmbossedView.h"
  27. #include "LAGAGroupBox.h"
  28. #include "LAGASeparator.h"
  29. #include "LAGADialogBox.h"
  30. #include "LAGAWindow.h"
  31. #include "CAboutBoxDB.h"
  32.  
  33. #include "LPPobView.h"
  34. #include "LAGAPopupMenu.h"
  35. #include "LAGAPointedVSlider.h"
  36. #include "LAGAPointedHSlider.h"
  37. #include "LAGASquareVSlider.h"
  38. #include "LAGASquareHSlider.h"
  39.  
  40. #include "LAGAProgressIndicator.h"
  41. #include "LAGAIndetermProgress.h"
  42.  
  43. #include "LAGADiscloTriangle.h"
  44. #include "LAGALittleArrows.h"
  45.  
  46. // put declarations for resource ids (ResIDTs) here
  47.  
  48. const ResIDT    window_Sample        = 1;    // EXAMPLE
  49.  
  50.  
  51. // ===========================================================================
  52. //        • Main Program
  53. // ===========================================================================
  54.  
  55. void main(void)
  56. {
  57.                                     // Set Debugging options
  58.     SetDebugThrow_(debugAction_Alert);
  59.     SetDebugSignal_(debugAction_Alert);
  60.  
  61.     InitializeHeap(3);                // Initialize Memory Manager
  62.                                     // Parameter is number of Master Pointer
  63.                                     //   blocks to allocate
  64.     
  65.                                     // Initialize standard Toolbox managers
  66.     UQDGlobals::InitializeToolbox(&qd);
  67.     
  68.     new LGrowZone(20000);            // Install a GrowZone function to catch
  69.                                     //    low memory situations.
  70.  
  71.     AGADemoApp theApp;            // replace this with your App type
  72.     theApp.Run();
  73. }
  74.  
  75.  
  76. // ---------------------------------------------------------------------------
  77. //        • CPPStarterApp             // replace this with your App type
  78. // ---------------------------------------------------------------------------
  79. //    Constructor
  80.  
  81. AGADemoApp::AGADemoApp()
  82.  
  83. {
  84.     // Register functions to create core PowerPlant classes
  85.     
  86.     RegisterAllPPClasses();
  87.     
  88.     //    Register AGA classes
  89.     RegisterAGAIndexTab();
  90.     LAGAIconButton::RegisterClass();
  91.     LAGAEmbossedView::RegisterClass();
  92.     LAGACheckBox::RegisterClass();
  93.     LAGARadioButton::RegisterClass();
  94.     LAGAWindow::RegisterClass();
  95.     LAGAEditField::RegisterClass();
  96.     LAGAGroupBox::RegisterClass();
  97.     LAGAPushButton::RegisterClass();
  98.     LAGASecondaryGroupBox::RegisterClass();
  99.     LAGASeparator::RegisterClass();
  100.     LAGADialogBox::RegisterClass();
  101.     LAGAWindow::RegisterClass();
  102.     URegistrar::RegisterClass(CAboutBoxDB::class_ID, (ClassCreatorFunc)CAboutBoxDB::CreateAboutBoxDBStream);
  103.     
  104.     URegistrar::RegisterClass(LPPobView::class_ID, (ClassCreatorFunc)LPPobView::CreatePPobViewStream);
  105.     LAGAPopupMenu::RegisterClass();
  106.     LAGAPointedVSlider::RegisterClass();
  107.     LAGAPointedHSlider::RegisterClass();
  108.     LAGASquareVSlider::RegisterClass();
  109.     LAGASquareHSlider::RegisterClass();
  110.     
  111.     LAGAProgressIndicator::RegisterClass();
  112.     LAGAIndetermProgress::RegisterClass();
  113.  
  114.     LAGADiscloTriangle::RegisterClass();
  115.     LAGALittleArrows::RegisterClass();
  116.  
  117.     //    Quick&Dirty object to animate the determinate progress indicator
  118.     URegistrar::RegisterClass(CProgressAnimator::class_ID, (ClassCreatorFunc)CProgressAnimator::CreateProgressAnimatorStream);
  119. }
  120.  
  121.  
  122. // ---------------------------------------------------------------------------
  123. //        • ~CPPStarterApp            // replace this with your App type
  124. // ---------------------------------------------------------------------------
  125. //    Destructor
  126. //
  127.  
  128. AGADemoApp::~AGADemoApp()
  129.  
  130. {
  131. }
  132.  
  133. // ---------------------------------------------------------------------------
  134. //        • StartUp
  135. // ---------------------------------------------------------------------------
  136. //    This function lets you do something when the application starts up. 
  137. //    For example, you could issue your own new command, or respond to a system
  138. //  oDoc (open document) event.
  139.  
  140. void AGADemoApp::StartUp()
  141.  
  142. {
  143.     ObeyCommand(cmd_New, nil);        // EXAMPLE, create a new window
  144. }
  145.  
  146. // ---------------------------------------------------------------------------
  147. //        • ObeyCommand
  148. // ---------------------------------------------------------------------------
  149. //    Respond to commands
  150.  
  151. Boolean AGADemoApp::ObeyCommand (CommandT inCommand, void *ioParam)
  152. {
  153.     Boolean        cmdHandled = true;
  154.  
  155.     switch (inCommand)
  156.         {
  157.     
  158.         // Deal with command messages (defined in PP_Messages.h).
  159.         // Any that you don't handle will be passed to LApplication
  160.              
  161.         case cmd_New:
  162.                                         // EXAMPLE, create a new window
  163.             LWindow        *theWindow;
  164.             theWindow = LWindow::CreateWindow(window_Sample, this);
  165.             UReanimator::LinkListenerToControls(this, theWindow, window_Sample);
  166.             theWindow->Show();
  167.             break;
  168.  
  169.         default:
  170.             cmdHandled = LApplication::ObeyCommand(inCommand, ioParam);
  171.             break;
  172.     }
  173.     
  174.     return cmdHandled;
  175. }
  176.  
  177. // ---------------------------------------------------------------------------
  178. //        • FindCommandStatus
  179. // ---------------------------------------------------------------------------
  180. //    This function enables menu commands.
  181. //
  182.  
  183. void AGADemoApp::FindCommandStatus (    CommandT inCommand, Boolean &outEnabled,
  184.                                                                                 Boolean &outUsesMark, Char16 &outMark,
  185.                                                                                 Str255 outName)
  186. {
  187.  
  188.     switch (inCommand)
  189.         {
  190.     
  191.             // Return menu item status according to command messages.
  192.             // Any that you don't handle will be passed to LApplication
  193.  
  194.             case cmd_New:                    // EXAMPLE
  195.                 outEnabled = true;            // enable the New command
  196.                 break;
  197.  
  198.             default:
  199.                 LApplication::FindCommandStatus(inCommand, outEnabled,
  200.                                                     outUsesMark, outMark, outName);
  201.                 break;
  202.         }
  203. }
  204.  
  205. void AGADemoApp::ShowAboutBox()
  206.  
  207. {
  208.     LAGADialogBox *theDialog;
  209.     theDialog = (LAGADialogBox *)LWindow::CreateWindow(999, this );
  210.     Assert_(theDialog != nil);
  211.     theDialog->Show();
  212. }
  213.  
  214. void AGADemoApp::ListenToMessage (MessageT inMessage, void *ioParam)
  215.  
  216. {
  217.     if (inMessage == -10009)
  218.         ShowAboutBox();
  219. }
  220.  
  221. //----------------------------------------------------------------------------------------------------------------
  222.  
  223. CProgressAnimator* CProgressAnimator::CreateProgressAnimatorStream (LStream* inStream)
  224.  
  225. {
  226.     return(new CProgressAnimator(inStream));
  227. }
  228.  
  229. CProgressAnimator::CProgressAnimator (LStream *inStream) : LView(inStream)
  230.  
  231. {
  232. }
  233.  
  234. void CProgressAnimator::FinishCreateSelf ()
  235.  
  236. {
  237.     StartIdling();
  238. }
  239.  
  240. void CProgressAnimator::SpendTime (const EventRecord &inMacEvent)
  241.  
  242. {
  243.     static long time = 0;
  244.     static Boolean up = true;
  245.     
  246.     if (::TickCount() > time)
  247.         {
  248.             LView *start = GetSuperView();
  249.             LView *theWindow;
  250.             while (start)
  251.                 {
  252.                     theWindow = start;
  253.                     start = start->GetSuperView();
  254.                 }
  255.             LAGAProgressIndicator *thePI = (LAGAProgressIndicator *)theWindow->FindPaneByID(2003);
  256.             if (thePI != nil)
  257.                 {
  258.                     Int32 max = thePI->GetMaxValue();
  259.                     Int32 val = thePI->GetValue();
  260.                     Int32 min = thePI->GetMinValue();
  261.                     if (up)
  262.                         {
  263.                             if (val >= max)
  264.                                 up = false;
  265.                             else
  266.                                 thePI->IncrementValue();
  267.                         }
  268.                     else
  269.                         {
  270.                             if (val <= min)
  271.                                 up = true;
  272.                             else
  273.                                 thePI->SetValue(val - 1);
  274.                         }
  275.                 }
  276.             time = TickCount() + 10;
  277.         }
  278. }
  279.  
  280.